package com.example.administrator.zyfypt_211dsh.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;


import com.example.administrator.zyfypt_211dsh.R;
import com.example.administrator.zyfypt_211dsh.adapter.AttentionAdapter;
import com.example.administrator.zyfypt_211dsh.bean.AttentionBean;
import com.example.administrator.zyfypt_211dsh.bean.SessionID;
import com.example.administrator.zyfypt_211dsh.iface.AttentionListener;
import com.example.administrator.zyfypt_211dsh.model.AttentionModel;

import java.util.List;

public class activity_attention extends AppCompatActivity {


    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private List<AttentionBean> list = null;
    private AttentionAdapter attentionAdapter;
    private AttentionListener attentionListener = new AttentionListener() {
        @Override
        public void onResponse(List<AttentionBean> beanlist) {
            list=beanlist;
            attentionAdapter.setList(list);
            attentionAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(activity_attention.this, "fail" + msg, Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_attention);
        AttentionModel attentionModel = new AttentionModel();
        attentionModel.getResultList("user", 1, SessionID.sessionID, attentionListener);
        initRecyclerView();
    }

    private void initRecyclerView() {
        layoutManager = new LinearLayoutManager(this);
        recyclerView = (RecyclerView)findViewById(R.id.recyclerView_attention);
        //创建默认线性布局
        recyclerView.setLayoutManager(layoutManager);
        //固定每个item的高度，可以提高性能
        recyclerView.setHasFixedSize(true);
        //获取数据
        attentionAdapter = new AttentionAdapter(this);
        recyclerView.setAdapter(attentionAdapter);
    }

}
